/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyTableTest5.java
 *
 * Created on Aug 21, 2008, 8:37:23 AM
 */

package swingtest.table;

import java.util.Calendar;
import java.util.LinkedList;
import swingtest.table.entity.MyEntity;

/**
 *
 * @author dyego
 */
public class MyTableTest5 extends javax.swing.JDialog {

    private java.util.List<swingtest.table.entity.MyEntity>  listOfEntitys = new LinkedList<MyEntity>();
    
    /** Creates new form MyTableTest5 */
    public MyTableTest5(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initMyComponents();
        initComponents();
        initTheTable();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MyTableTest5 dialog = new MyTableTest5(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables


    
    private void initMyComponents() {
        for (int i = 0; i < 20; i++) {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, i);

            MyEntity entity = new MyEntity();
            entity.setId(i);
            entity.setName("My Name "+i);
            entity.setAge(i+20);
            entity.setBorn(cal.getTime());
            entity.setType(swingtest.table.entity.EntityType.TYPE1);
            listOfEntitys.add(entity);
        }

    }

    private void initTheTable() {
        jTable1.setModel(new MyTableModel(MyEntity.class,listOfEntitys,jTable1));
    }

}
